def isValid(s):
    re = []
    zi = {
        "(": ")",
        "[": "]",
        "{": "}",
    }
    g, g1 = 0, 0
    for i in s:
        if i in ['(', '[', '{']:
            re.append(i)
            g1 = g1 + 1
        else:
            if re:
                a = re.pop()
                if zi.get(a) == i:
                    g = g + 1
    if g == g1:
        return True
    else:
        return False


if __name__ == '__main__':
    s = "{[]}"
    print(isValid(s))
